﻿String.prototype.format = function () {
    var s = this;
    for ( var i = 0; i < arguments.length; ++i ) {
        var reg = RegExp( '\\{' + i + '\\}', "gm" );
        s = s.replace( reg, arguments[i] );
    }
    return s;
}

var Utils = function () {
    return {
        getDateTime: function () {
            return $.formatDateTime( 'yy-mm-dd hh:ii:ss', new Date() );
        },
        log: function ( msg ) {
            console.log( msg );
        },
        setCookie: function ( name, value ) {
            var expireDays = 300;
            var exDate = new Date();
            exDate.setDate( exDate.getDate + expireDays );
            document.cookie = "{0}={1}{2}".format( name, escape( value ), expireDays ? ";expires=" + exDate.toGMTString() : "" );
        },
        delCookie: function ( name ) {
            var exDate = new Date();
            exDate.setDate( exDate.getDate - 1 );
            var value = unescape( getCookie( name ) );
            document.cookie = "{0}={1};expires={2}".format( name, value, exDate );
        },
        getCookie: function ( name ) {
            var value = document.cookie.match( new RegExp( "(^| )" + name + "=([^;]*)(;|$)" ) );
            return value[2];
        }
    };
} ();